package com.cn.wanxi.servlet.front;

import com.cn.wanxi.model.CompanyModel;
import com.cn.wanxi.model.NavModel;
import com.cn.wanxi.model.ProductModel;
import com.cn.wanxi.service.ICompanyService;
import com.cn.wanxi.service.INavService;
import com.cn.wanxi.service.IProductService;
import com.cn.wanxi.service.impl.CompanyServiceImpl;
import com.cn.wanxi.service.impl.NavServiceImpl;
import com.cn.wanxi.service.impl.ProductServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/home")//必须有/斜杠
public class HomeServlet extends HttpServlet {
    ICompanyService companyService = new CompanyServiceImpl();
    INavService navService = new NavServiceImpl();
//    IPictureRotationService pictureRotationService = new PictureRotationServiceImpl();
    IProductService productService = new ProductServiceImpl();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        CompanyModel companyModel = companyService.getCompany();
        List<NavModel> navList = navService.getNavList();
//        List<PictureRotationModel> pictures = pictureRotationService.getPictures();
        List<ProductModel> pictures = productService.getProductList();
        req.setAttribute("company", companyModel);
        req.setAttribute("nav",navList);
        req.setAttribute("pictures",pictures);
        req.getRequestDispatcher("/jsp/home.jsp").forward(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doPost(req, resp);
    }
}
